// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-04-07 17:18
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.DateTrain;

import org.junit.jupiter.api.Test;

public class RotateString {
    /**
     * 旋转字符串：判断源字符串是否可以通过旋转实现目标字符串
     */
    public boolean rotateString(String s, String goal) {
        int n = s.length();
        if (s.equals(goal)) {
            return true;
        }
        for (int i = 0; i < n; i++) {
            s = rotate(s);
            if (s.equals(goal)) {
                return true;
            }
        }
        return false;
    }

    private String rotate(String s) {
        return s.substring(1, s.length()) + s.charAt(0);
    }

    @Test
    public void shout() {
        String s = "abcde";
        String goal = "cdeab";
        System.out.println(rotateString(s, goal));
    }
}
